package com.example.automobile_positioning.activity;

import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.automobile_positioning.R;
//import com.example.automobile_positioning.activity.MapActivity;
import com.example.automobile_positioning.util.SPUtils;

public class SmsActivity extends Activity {
	private Map<String, ?> map;
	private TextView mLatitude;
	private TextView mLongitude;
	private TextView mTime;
	private EditText mNumber;
	private Button mBut;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sms);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题
		map = SPUtils.getAll(this);
		mBut = (Button) findViewById(R.id.send);
		mLatitude = (TextView) findViewById(R.id.Latitude);
		mLongitude = (TextView) findViewById(R.id.Longitude);
		mTime = (TextView) findViewById(R.id.time);
		mNumber = (EditText) findViewById(R.id.number);
		mLatitude.setText(String.valueOf(map.get("latitude")));
		mLongitude.setText(String.valueOf(map.get("longitude")));
		mTime.setText(String.valueOf(map.get("time")));
		
		
		
		final String strSms = "纬度:"+mLatitude.getText().toString()+",经度:"+mLongitude.getText().toString()+",时间:"+mTime.getText().toString();
		final SmsManager smsManager = SmsManager.getDefault();
		
		mBut.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (strSms.length() > 70) {
					List<String> msgs = smsManager.divideMessage(strSms);
					for (String msg : msgs) {
						smsManager.sendTextMessage(mNumber.getText().toString(), null, msg, null ,null);
					}
				} else {
					 smsManager.sendTextMessage(mNumber.getText().toString(), null, strSms, null ,null);
				}
				Toast.makeText(SmsActivity.this, "短信发送完成", Toast.LENGTH_LONG).show();
			}
		});
	}
	
}
